package com.ruoyi.bantong.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bantong.domain.BtRedbagConfig;
import com.ruoyi.bantong.service.IBtRedbagConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 红包玩法配置Controller
 * 
 * @author laohei
 * @date 2021-02-06
 */
@RestController
@RequestMapping("/bantong/redbagconfig")
public class BtRedbagConfigController extends BaseController
{
    @Autowired
    private IBtRedbagConfigService btRedbagConfigService;

    /**
     * 查询红包玩法配置列表
     */
    //@PreAuthorize("@ss.hasPermi('bantong:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(BtRedbagConfig btRedbagConfig)
    {
        startPage();
        List<BtRedbagConfig> list = btRedbagConfigService.selectBtRedbagConfigList(btRedbagConfig);
        return getDataTable(list);
    }

    /**
     * 导出红包玩法配置列表
     */
    //@PreAuthorize("@ss.hasPermi('bantong:config:export')")
    @Log(title = "红包玩法配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BtRedbagConfig btRedbagConfig)
    {
        List<BtRedbagConfig> list = btRedbagConfigService.selectBtRedbagConfigList(btRedbagConfig);
        ExcelUtil<BtRedbagConfig> util = new ExcelUtil<BtRedbagConfig>(BtRedbagConfig.class);
        return util.exportExcel(list, "config");
    }

    /**
     * 获取红包玩法配置详细信息
     */
    //@PreAuthorize("@ss.hasPermi('bantong:config:query')")
    @GetMapping(value = "/{type}")
    public AjaxResult getInfo(@PathVariable("type") Integer type)
    {
        return AjaxResult.success(btRedbagConfigService.selectBtRedbagConfigById(type));
    }

    /**
     * 新增红包玩法配置
     */
    //@PreAuthorize("@ss.hasPermi('bantong:config:add')")
    @Log(title = "红包玩法配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BtRedbagConfig btRedbagConfig)
    {
        return toAjax(btRedbagConfigService.insertBtRedbagConfig(btRedbagConfig));
    }

    /**
     * 修改红包玩法配置
     */
    //@PreAuthorize("@ss.hasPermi('bantong:config:edit')")
    @Log(title = "红包玩法配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BtRedbagConfig btRedbagConfig)
    {
        return toAjax(btRedbagConfigService.updateBtRedbagConfig(btRedbagConfig));
    }

    /**
     * 删除红包玩法配置
     */
    //@PreAuthorize("@ss.hasPermi('bantong:config:remove')")
    @Log(title = "红包玩法配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{types}")
    public AjaxResult remove(@PathVariable Integer[] types)
    {
        return toAjax(btRedbagConfigService.deleteBtRedbagConfigByIds(types));
    }
}
